/**
 * Created with IntelliJ IDEA.
 * User: duoba
 * Date: 16/2/23
 * Time: 下午7:28
 * To change this template use File | Settings | File Templates.
 */

package com.cake21.uitest.System.Core;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import com.cake21.uitest.System.Driver.ExtendWebDriver;

public abstract class Page {

    /*构建方法*/
    public Page() {
        PageFactory.initElements(driver, this);
        load();
    }

    /*浏览器对象实例*/
    protected Browser browser = initBrowser();

    /*初始化浏览器对象实例*/
    protected Browser initBrowser() {
        return Server.getCommander().getThreadMap().get(Thread.currentThread().getId());
    }

    /*浏览器测试驱动*/
    protected WebDriver driver = initDriver();

    /*初始化浏览器测试驱动*/
    protected WebDriver initDriver() {
        return browser.getDriver();
    }

    /*扩展浏览器测试驱动*/
    protected ExtendWebDriver driverx = initDriverx();

    /*初始化扩展浏览器测试驱动*/
    protected ExtendWebDriver initDriverx() {
        return new ExtendWebDriver(driver);
    }

    /*页面载入执行代码*/
    protected void load() {
        /*基类不做任何事*/
    }

    /*获得页面Title*/
    public String getPageTitle() {
        return driver.getTitle();
    }

    /*获得WebDriver实例*/
    public WebDriver getDriver() {
        return driver;
    }

}
